package xdu.lz.stage2_design_pattern.chapter11_up_down_context_pattern;



public class ExecutionTask implements Runnable {

    //模拟从数据库拿出数据的操作
    private QueryFromDBAction queryFromDBAction = new QueryFromDBAction();
    //模拟从互联网拿数据
    private QueryFromHttpAction httpAction = new QueryFromHttpAction();

    @Override
    public void run() {

        //不需要传参,操作的就是当前线程绑定的唯一对象的上下文
        //take data from db and set the data into context Obj
        queryFromDBAction.execute();
        System.out.println("the name query successful");
        //take data from web and set data into context Obj
        httpAction.execute();
        //ActionContext.getActionContext()拿到的是当前线程绑定的唯一Context对象

        Context context = ActionContext.getActionContext().getContext();
        System.out.println("the cardId query successful");
        System.out.println("name :"+context.getName() + "  card id:"+context.getCardId());
    }
}
